package com.iflytek.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.entity.Dept;
import com.iflytek.service.DeptService;
import com.iflytek.mapper.DeptMapper;
import org.springframework.stereotype.Service;

/**
 * @author Windows
 * @description 针对表【t_dept】的数据库操作Service实现
 * @createDate 2022-09-11 16:27:23
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept>
        implements DeptService {

    @Override
    public void markDept(String code) {
        this.getBaseMapper().UpdateDel(code);
    }

    @Override
    public void saveDept(Dept department) throws Exception {
        QueryWrapper<Dept> w = new QueryWrapper<Dept>().eq("dept_name", department.getDeptName());
        Dept dept = this.getBaseMapper().selectOne(w);
        if (dept == null || (dept != null && dept.getDeptCode().equals(department.getDeptCode()))) {
            this.getBaseMapper().updateById(department);
        } else throw new Exception("部门名称已存在");

    }

    @Override
    public void createDept(Dept department) throws Exception {
        QueryWrapper<Dept> w = new QueryWrapper<Dept>().eq("dept_name", department.getDeptName());
        Dept dept = this.getBaseMapper().selectOne(w);
        if (dept == null ) {
            this.getBaseMapper().insert(department);
        } else throw new Exception("部门名称已存在");

    }
}




